package cn.shawrainia.notedemo.web.controller;

import cn.shawrainia.notedemo.domain.User;
import cn.shawrainia.notedemo.service.INoteService;
import com.tencentcloudapi.sms.v20210111.models.SendStatusStatisticsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class NoteController {

    @Autowired
    private INoteService noteService;

    //发送短信
    @GetMapping("/sendMsg")
    public String note(Long userId,String phone){
        User user = noteService.send(userId, phone);
        System.out.println("用户id:" + user.getUserId());
        System.out.println("用户手机:" + user.getPhone());
        System.out.println("用户验证码:" + user.getCode());
        return "发送成功";
    }

    //统计短信发送数量
    @GetMapping("/statisticalSms")
    public String SendStatusStatistics(String beginTime,String endTime){
        //时间，yyyymmddhh 需要拉取的截止时间，精确到小时
        //注：EndTime 必须大于 beginTime
        //String beginTime = "2022020600";
        //String endTime = "2022020623";
        SendStatusStatisticsResponse statisticalSms = noteService.SendStatusStatistics(beginTime, endTime);
        System.out.println("短信发送成功计数:" + statisticalSms.getSendStatusStatistics().getRequestSuccessCount());
        return SendStatusStatisticsResponse.toJsonString(statisticalSms);
    }
}